#include "NpcControlledObject.h"
#include "include.h"

NpcControlledObject::NpcControlledObject(    TextureManager * textureManager,
			  char * textureName,
			  Vector2D position,
			  Vector2D * vertices,
			  int numVertices,
			  float mass,
			  Vector2D size, 
			  char * dialogueFile,
			  char * name)
:CpuControlledObject(textureManager, position, mass, NULL, NULL, NULL, size,textureName, textureName)
{
	if(dialogueFile)
	{
		dialogueManager = new DialogueManager(dialogueFile);
	}
	material->isGrabbable = false;
	this->name = name;
}
			  
NpcControlledObject::~NpcControlledObject()
{
	if(dialogueManager)
	{
		delete(dialogueManager);
		dialogueManager = NULL;
	}
	if(name)
	{
		delete(name);
		name = NULL;
	}
}
char * NpcControlledObject::Activate(Dictionary * gameState)
{
	return dialogueManager->Speak(gameState);
}
char * NpcControlledObject::GetName()
{
	return name;
}
char * NpcControlledObject::Action(Vector2D playerPos, Dictionary * gameState)
{
	printf("Checking action, distance = %f\n", playerPos.dist(position));
	if(playerPos.dist(position) < MAX_TALK_DISTANCE)
	{
		return Activate(gameState);
	}
	return NULL;
}
Vector2D * NpcControlledObject::GetWallPoseCoordinates()
{
	Vector2D * poseCoordinates = (Vector2D *)malloc(sizeof(Vector2D) * 4);
	memcpy(poseCoordinates, textureVertices, sizeof(Vector2D) * 4);
	return poseCoordinates;	
}
bool NpcControlledObject::GetFreeRotate()
{
	return false;
}